<template>
  <div class="user-wrapper">
    <div class="content-box">
      <div class="welcome-text" />
      <a v-if="showHelp" href="https://www.yuque.com/uvhsrh/dtb6pw" target="_blank">
        <span class="action">
          <a-icon type="question-circle-o" />
        </span>
      </a>
      <notice-icon class="action" />
      <a-dropdown>
        <span class="action ant-dropdown-link user-dropdown-menu">
          <a-avatar v-if="avatar" class="avatar" size="small" :src="avatar" />
          <a-avatar v-else class="avatar" size="small" src="/avatar2.jpg" />
          <span>{{ nickname }}</span>
        </span>
        <a-menu slot="overlay" class="user-dropdown-menu-wrapper">

          <!-- <a-menu-item key="0">
            <nuxt-link to="/system/Account">
              <a-icon type="setting" />
              <span>账户设置</span>
            </nuxt-link>
          </a-menu-item>

          <a-menu-divider /> -->

          <a-menu-item key="0">
            <a href="javascript:;" @click="handleLogout">
              <a-icon type="logout" />
              <span>退出登录</span>
            </a>
          </a-menu-item>
        </a-menu>
      </a-dropdown>
    </div>
  </div>
</template>

<script>
import NoticeIcon from '@/components/NoticeIcon'

export default {
  name: 'UserMenu',
  components: {
    NoticeIcon
  },
  props: {
    showHelp: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      dayNow: '',
      current: ''
    }
  },
  computed: {
    avatar () {
      return this.$get(this, '$store.state.auth.user.avatar', '')
    },
    nickname () {
      return this.$get(this, '$store.state.auth.user.nickname', '')
    }
  },
  created () {
    const date = new Date()
    const year = date.getFullYear()
    const month = date.getMonth()
    const day = date.getDate()
    this.dayNow = year + '年' + (month + 1) + '月' + day + '日'
  },
  methods: {
    handleLogout () {
      const that = this

      this.$confirm({
        centered: true,
        title: '提示',
        content: '真的要注销登录吗 ?',
        onOk () {
          that.$auth.logout().then(() => {
            window.location.reload()
          }).catch(err => {
            that.$message.error({
              title: '错误',
              description: err.message
            })
          })
        },
        onCancel () {
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.content-box{
  .welcome-text{
    float: left;
    font-size: 14px;
    span:nth-child(2){
      padding-left: 10px;
      color:#298AFB;
    }
  }
}
</style>
